﻿// UpdaterOptionsPage.cs
//
// Copyright (c) 2007 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;
using System.Windows.Input;
using Supremacy.Annotations;
using Supremacy.Client;
using Supremacy.Resources;

namespace Supremacy.Updater
{
    /// <summary>
    /// Interaction logic for UpdaterOptionsPage.xaml
    /// </summary>
    public partial class UpdaterOptionsPage : IClientOptionsPage
    {
        public static readonly RoutedCommand CheckForUpdatesCommand = new RoutedCommand(
            "CheckForUpdates",
            typeof(UpdaterOptionsPage));

        public static readonly RoutedCommand ClearUpdaterRegistryCommand = new RoutedCommand(
            "ClearUpdaterRegistry",
            typeof(UpdaterOptionsPage));

        private readonly IResourceManager _resourceManager;
        private readonly IUpdaterService _updaterService;

        public UpdaterOptionsPage(
            [NotNull] IResourceManager resourceManager,
            [NotNull] IUpdaterService updaterService)
        {
            if (resourceManager == null)
                throw new ArgumentNullException("resourceManager");
            if (updaterService == null)
                throw new ArgumentNullException("updaterService");

            InitializeComponent();

            _resourceManager = resourceManager;
            _updaterService = updaterService;

            CommandBindings.Add(
                new CommandBinding(
                    CheckForUpdatesCommand,
                    (sender, e) => _updaterService.CheckForUpdates(),
                    (sender, e) => e.CanExecute = _updaterService.CanCheckForUpdates));

            CommandBindings.Add(
                new CommandBinding(
                    ClearUpdaterRegistryCommand,
                    (sender, e) => _updaterService.ClearUpdaterRegistry()));
        }

        #region Implementation of IClientOptionsPage
        public string Header
        {
            get { return _resourceManager.GetString("SETTINGS_UPDATER_TAB"); }
        }
        #endregion
    }
}
